package com.guc.servlet;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 处理用户登陆请求
 */
public class UserServlet extends HttpServlet {
    //处理get请求
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String loginname = req.getParameter("loginname");//用户名
        String pwdname = req.getParameter("pwdname");//密码
        //登陆业务的逻辑
        if(loginname!=null&&pwdname!=null&&loginname.equals("admin")&&pwdname.equals("admin")){
            //登陆成功
            System.out.println("登陆成功，loginname="+loginname+";pwdname="+pwdname);
            //发送数据到页面
            req.setAttribute("msg","登陆成功，loginname="+loginname+";pwdname="+pwdname);
        }else{
            //登陆失败
            System.out.println("登陆失败，loginname="+loginname+";pwdname="+pwdname);
            //发送数据到页面
            req.setAttribute("msg","登陆失败，loginname="+loginname+";pwdname="+pwdname);
        }
        //转发到新的页面
        req.getRequestDispatcher("user.jsp").forward(req,resp);
    }
    //处理post请求
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
//    只是参考
}
